﻿using System.Collections.Generic;

namespace MahaBaseWrapper
{
    /// <summary>
    /// Represent the Select Task
    /// </summary>
    /// <typeparam name="T">Entity to be selected</typeparam>
    public sealed class Select<T> where T : class
    {
        /// <summary>
        /// Current instace of QueryProcessor Class
        /// </summary>
        private Core.QueryProcessor<T> _processor;

        /// <summary>
        /// The constructor for Select task, this is method allow to create a instance of the Select class and perform select against the database.
        /// </summary>
        public Select()
        {
            this._processor = new MahaBaseWrapper.Core.QueryProcessor<T>();
        }

        /// <summary>
        /// Method used to set conditions for the select task.
        /// 
        /// Conditions must be passed like "WHERE ID = 1"
        /// </summary>
        /// <param name="conditions">
        /// Conditions for the update task
        /// 
        /// Conditions must be passed like "WHERE ID = 1"
        /// </param>
        /// <returns>The current instance of Select class</returns>
        public Select<T> WithConditions(string conditions)
        {
            this._processor.Conditions = conditions;

            return this;
        }

        /// <summary>
        /// Method used to perform the configured select against database.
        /// </summary>
        /// <returns>Unique result for select instance</returns>
        public T GetOne()
        {
            return this._processor.PerformSelectOne();
        }

        /// <summary>
        /// Method used to perform the configured select against database.
        /// </summary>
        /// <returns>List of result matching the configured instance of select</returns>
        public List<T> Get()
        {
            return this._processor.PerformSelectMany();
        }
    }
}